package com.lma.crm.page;

import java.util.List;

public class PageBean<T> {

	//必须项
	private int pageNum;		//第几页（当前页）
	private int pageSize;		//页面大小
	private int totalRecord;	//总记录数
	//计算项
	private int startIndex;		//开始索引
	private int totalPage;		//总页数
	
	//动态显示条
	private int start;
	private int end;
	
	//分页查询数据
	private List<T> data;
	
	public PageBean(int pageNum, int pageSize, int totalRecord) {
		super();
		this.pageNum = pageNum;
		this.pageSize = pageSize;
		this.totalRecord = totalRecord;
		
		//计算开始索引
		this.startIndex = (this.pageNum - 1) * this.pageSize;
		//计算总分页数
		this.totalPage = (this.totalRecord + this.pageSize - 1) / pageSize;
		
		//动态显示条
		this.start = 1;
		this.end = 10;
		
		if(this.totalPage <= 10) {
		    this.end = this.totalPage;
		} else {
		    this.start = this.pageNum - 5;
		    this.end = this.pageNum + 4;
		    
		    if(this.start < 1) {
		        this.start = 1;
		        this.end = 10;
		    }
		    
		    if(this.end > this.totalPage) {
		        this.end = this.totalPage;
		        this.start = this.end - 9;
		    }
		    
		}
	}
	
	public int getPageNum() {
		return pageNum;
	}
	
	public void setPageNum(int pageNum) {
		this.pageNum = pageNum;
	}
	
	public int getPageSize() {
		return pageSize;
	}
	
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	
	public int getTotalRecord() {
		return totalRecord;
	}
	
	public void setTotalRecord(int totalRecord) {
		this.totalRecord = totalRecord;
	}
	
	public int getStartIndex() {
		return startIndex;
	}
	
	public void setStartIndex(int startIndex) {
		this.startIndex = startIndex;
	}
	
	public int getTotalPage() {
		return totalPage;
	}
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public List<T> getData() {
		return data;
	}

	public void setData(List<T> data) {
		this.data = data;
	}

    public int getStart() {
        return start;
    }

    public void setStart(int start) {
        this.start = start;
    }

    public int getEnd() {
        return end;
    }

    public void setEnd(int end) {
        this.end = end;
    }
	
}
